// 导入用户集合
const { Category } = require('../../../model/category');
const { ChildCategory } = require('../../../model/childCategory');

module.exports = async (req, res) => {
  const { name, icon, parentId: parent } = req.body
  const create = (model) => {
    model.create({
      name, icon, parent
    }).then(item => {
      res.json({
          data: item,
          message: '添加成功！'
      })
    }).catch((err) => {
      res.status(403)
      res.json({
          log: err,
          message: '添加失败！'
      })
    })
  }
  create(req.body.parentId ? ChildCategory : Category)
}